(function () {
    var EVENT_CLICK = Laya.Event.CLICK;
    var io = ppt.io;

    function PropsPage(call) {
        PropsPage.super(this);
        this._listNum = [];
        this._picall = [];
        this.callback = call;
        this.data = null;
        this.init();
    }
    Laya.class(PropsPage, "Com.Props.Page", ui.Props.PropsPageUI);
    var _proto = PropsPage.prototype;

    _proto.init = function () {
        this.propsList.selectHandler = new laya.utils.Handler(this, this.onSelect);
        this.propsList.renderHandler = new laya.utils.Handler(this, this.listprops);
    }
    _proto.listprops = function (props, index) {

        props.getChildByName('picall').skin = 'res/props/' + this.data[index].item_id + '.png';
        
    }
    _proto.titleChange = function (selectedIndex) {
        if (selectedIndex == 0) {
            this.bagTitle.index = 0;
        }
        else if (selectedIndex == 1) {
            this.bagTitle.index = 1;
        }
        else if (selectedIndex == 2) {
            this.bagTitle.index = 2;
        }
    }
    //选择背包中的商品
    _proto.onSelect = function (index) {
        console.log("Props List Selected");
        if(index == -1){return;}
        for(var i in this.data){
            var data = this.data[i];
            console.log(i, index);
            if(i == index){
                data.picbg = 1;
            }else{
                data.picbg = 0;
            }
            this.propsList.setItem(i, data);
        }
        this._index = index;
        this.callback(index);
    }
    //背包更新数据
    _proto.upData = function (data) {
        console.log("Props List Update");
        this.propsList.selectedIndex = -1;
        var data = data.bag;
        this.data = data;

        for (var i = 0; i < data.length; i++) {
            data[i].listNum = 'x'+ data[i].count;
        }
        this.propsList.array = data;

        this.propsList.selectedIndex = this._index = 0;
    }
})();